import request from "@/utils/request";

export function login(data) {
  return request({
    url: "/user/login",
    method: "post",
    data,
  });
}

export function getInfo(token) {
  return request({
    url: "/user/info",
    method: "get",
    params: { token },
  });
}

export function getOnLineCount() {
  return request({
    url: "/user/getOnLineCount",
    method: "get",
  });
}

export function logout(token) {
  return request({
    url: "/user/logout",
    method: "post",
    params: { token },
  });
}

export function regesiter(data) {
  if (data.subject && data.subject.length > 0) {
    data.subject = JSON.stringify(data.subject);
  } else {
    data.subject = null;
  }
  return request({
    url: "/user/regesiter",
    method: "post",
    data,
  });
}

export function setPassword(data) {
  return request({
    url: "/user/setPassword",
    method: "post",
    data,
  });
}

export function updateName(name) {
  return request({
    url: `/user/updateName/${name}`,
    method: "put",
  });
}

export function list(name, account, currentPage, pageSize) {
  name = name ? name : "_";
  account = account ? account : 0;
  return request({
    url: `/user/list/${name}/${account}/${currentPage}/${pageSize}`,
    method: "get",
  });
}

export function getTotal(name, account) {
  name = name ? name : "_";
  account = account ? account : 0;
  return request({
    url: `/user/getTotal/${name}/${account}`,
    method: "get",
  });
}

export function detele(id) {
  return request({
    url: `/user/delete/${id}`,
    method: "delete",
  });
}

export function resetPassword(id, password) {
  return request({
    url: `/user/resetPassword/${id}/${password}`,
    method: "put",
  });
}

export function update(data) {
  if (data.subject && data.subject.length > 0) {
    data.subject = JSON.stringify(data.subject);
  } else {
    data.subject = null;
  }
  return request({
    url: `/user/update`,
    method: "post",
    data,
  });
}

//查询没有设置班级信息的学员
export function getStudents() {
  return request({
    url: "/user/getStudents",
    method: "get",
  });
}

export function getTeachers() {
  return request({
    url: "/user/getTeachers",
    method: "get",
  });
}

export function getAllStudents() {
  return request({
    url: "/user/getAllStudents",
    method: "get",
  });
}

//查询设置了班级信息的学员
export function getByGradeId(gradeId) {
  return request({
    url: `/user/getByGradeId/${gradeId}`,
    method: "get",
  });
}
